/*
 * @lc app=leetcode.cn id=383 lang=csharp
 *
 * [383] 赎金信
 */

// @lc code=start
public class Solution {
    public bool CanConstruct(string ransomNote, string magazine) {
        var dict = new Dictionary<char, int>();
        foreach (var c in magazine)
        {
            if (!dict.ContainsKey(c))
            {
                dict[c] = 1;
            }
            else
            {
                dict[c] += 1;
            }
        }
        foreach (var c in ransomNote)
        {
            if (!dict.ContainsKey(c) || dict[c] == 0)
            {
                return false;
            }
            dict[c] -= 1;
        }
        return true;
    
    }
}
// @lc code=end

